package org.wbd.pklib.db;

import javax.persistence.AssociationOverride;
import javax.persistence.AssociationOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
* klasa reprezentujaca obiekt w tabeli repo_user 
 */
@Entity
@Table(name = "repo_user")
@AssociationOverrides({
		@AssociationOverride(name = "repoUserJoin.repo", 
			joinColumns = @JoinColumn(name = "repoId")),
		@AssociationOverride(name = "repoUserJoin.user", 
			joinColumns = @JoinColumn(name = "userId"))})
public class RepoUser implements java.io.Serializable{
	private RepoUserJoin repoUserJoin  = new RepoUserJoin();
	private String function;
	
	public RepoUser(){
		
	}
	
	@EmbeddedId
	public RepoUserJoin getRepoUserJoin() {
		return repoUserJoin;
	}
	public void setRepoUserJoin(RepoUserJoin repoUserJoin) {
		this.repoUserJoin = repoUserJoin;
	}
	
	@Column(name = "function", nullable = false, length = 32)
	public String getFunction() {
		return function;
	}
	public void setFunction(String function) {
		this.function = function;
	}
	
	@Transient
	public User getUser() {
		return getRepoUserJoin().getUser();
	}
 
	public void setUser(User user) {
		getRepoUserJoin().setUser(user);
	}
 
	@Transient
	public Repo getRepo() {
		return getRepoUserJoin().getRepo();
	}
 
	public void setRepo(Repo repo) {
		getRepoUserJoin().setRepo(repo);
	}
	
	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null || getClass() != o.getClass())
			return false;
 
		RepoUser that = (RepoUser) o;
 
		if (getRepoUserJoin() != null ? !getRepoUserJoin().equals(that.getRepoUserJoin())
				: that.getRepoUserJoin() != null)
			return false;
 
		return true;
	}
	
	public int hashCode() {
		return (getRepoUserJoin() != null ? getRepoUserJoin().hashCode() : 0);
	}
	
	

}
